package com.winning.dps.rda.common.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 *  Mybatis多数据源jdbcTemplate
 */
@Configuration
public class DataSourceConfig {

    @Value("${spring.datasource.dynamic.datasource.appsource.username}")
    private String appUsername;
    @Value("${spring.datasource.dynamic.datasource.appsource.password}")
    private String appPassword;
    @Value("${spring.datasource.dynamic.datasource.appsource.url}")
    private String appUrl;
    @Value("${spring.datasource.dynamic.datasource.appsource.driver-class-name}")
    private String appDriver;


    @Value("${spring.datasource.dynamic.datasource.dwsource.username}")
    private String dwUsername;
    @Value("${spring.datasource.dynamic.datasource.dwsource.password}")
    private String dwPassword;
    @Value("${spring.datasource.dynamic.datasource.dwsource.url}")
    private String dwUrl;
    @Value("${spring.datasource.dynamic.datasource.dwsource.driver-class-name}")
    private String dwDriver;

    @Bean(name = "appJdbcTemplate")
    public JdbcTemplate appJdbcTemplate() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUsername(appUsername);
        dataSource.setPassword(appPassword);
        dataSource.setUrl(appUrl);
        dataSource.setDriverClassName(appDriver);
        return new JdbcTemplate(dataSource);
    }


    @Bean(name = "dsJdbcTemplate")
    public JdbcTemplate dsJdbcTemplate() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUsername(dwUsername);
        dataSource.setPassword(dwPassword);
        dataSource.setUrl(dwUrl);
        dataSource.setDriverClassName(dwDriver);
        return new JdbcTemplate(dataSource);
    }



}

